package com.coolw.dynamic.thread.pool.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coolw.dynamic.thread.pool.constant.CommonStat;
import com.coolw.dynamic.thread.pool.entity.ThreadPoolConfigEntity;
import com.coolw.dynamic.thread.pool.entity.ThreadPoolConfigHisEntity;
import com.coolw.dynamic.thread.pool.mapper.ThreadPoolConfigHisMapper;
import com.coolw.dynamic.thread.pool.service.ThreadPoolConfigHisService;
import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.data.id.IdUtil;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 线程池配置变更历史Service实现类
 *
 * @author coolw
 * @date 2024/5/17 15:12
 */
@Service
public class ThreadPoolConfigHisServiceImpl extends ServiceImpl<ThreadPoolConfigHisMapper, ThreadPoolConfigHisEntity>
        implements ThreadPoolConfigHisService {

    @Override
    public boolean saveConfigHis(ThreadPoolConfigEntity configEntity) {
        if (Objects.isNull(configEntity)) {
            return false;
        }

        ThreadPoolConfigHisEntity configHisEntity = BeanUtil.copyProperties(configEntity, ThreadPoolConfigHisEntity.class
                , CommonStat.TABLE_COMMON_FIELD);
        configHisEntity.setHisPoolNo(IdUtil.getSnowflakeNextIdStr());
        return save(configHisEntity);
    }
}
